package com.ala4.oxcafe.controller;

import com.ala4.oxcafe.boot.page.PageDomain;
import com.ala4.oxcafe.boot.page.PageResult;
import com.ala4.oxcafe.domain.R;
import com.ala4.oxcafe.entity.DictData;
import com.ala4.oxcafe.entity.DictType;
import com.ala4.oxcafe.service.DictInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 字典信息管理
 *
 * @author PING
 * @version 1.0.0
 * @date 2025/8/14 10:48
 */
@RestController
@RequestMapping("/dict-info")
@AllArgsConstructor
@Tag(name = "字典管理", description = "用于管理字典信息")
public class DictInfoController {

    private final DictInfoService dictInfoService;

    @Operation(summary = "分页查询字典类型")
    @GetMapping("/type-page")
    public R<PageResult<DictType>> page(PageDomain pageDomain, DictType dictType) {
        return R.ok(PageResult.iPage(dictInfoService.dictTypePage(pageDomain, dictType)));
    }

    @Operation(summary = "根据字典类型查询字典数据")
    @GetMapping("/dict-data/{typeCode}")
    public R<List<DictData>> dictData(@Schema(description = "字典类型编码") @PathVariable String typeCode) {
        return R.ok(dictInfoService.dictData(typeCode));
    }

}
